import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../model/register_config.dart';
import '../model/register_config_req.dart';
import 'user_info_edit_avater_page.dart';

class UserInfoEditSexPage extends StatefulWidget {
  const UserInfoEditSexPage({super.key});

  @override
  State<UserInfoEditSexPage> createState() => _UserInfoEditSexPageeState();
}

class _UserInfoEditSexPageeState extends State<UserInfoEditSexPage> {
  int sex = 0;
  RegisterConfig? configModel;
  RegisterConfigReq req = RegisterConfigReq();
  @override
  void initState() {
    super.initState();
    requestPageConfigData();
  }

  void requestPageConfigData() {
    HttpProvider.get(
      '/user/getInfoInit',
      explain: '获取信息初始化数据',
      success: (result) {
        RegisterConfig config = RegisterConfig.fromJson(result.data);
        configModel = config;
        setState(() {});
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: SafeArea(
        top: false,
        child: Stack(
          children: [
            Image.asset('assets/app/images/auth/background_top_image.png'),
            Scaffold(
                appBar: BrnAppBar(title: '', backgroundColor: Colors.transparent),
                backgroundColor: Colors.transparent,
                body: Padding(
                  padding: EdgeInsets.symmetric(horizontal: 20.w),
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 32.h),
                      Padding(
                        padding: EdgeInsets.only(left: 16.0.w),
                        child: Text(configModel?.step1?.maintitle ?? '选择你的性别~',
                            style: TextStyle(
                                color: const Color(0xFF1E2733), fontSize: 27.sp, fontWeight: FontWeight.w600)),
                      ),
                      Padding(
                        padding: EdgeInsets.only(left: 16.0.w),
                        child: Text(configModel?.step1?.subtitle ?? '注册完成后，你的性别将无法更改',
                            style: TextStyle(color: const Color(0xFF999999), fontSize: 16.sp)),
                      ),
                      SizedBox(height: 40.h),
                      Stack(
                        children: [
                          Image.asset('assets/app/images/user_edit/user_edit_sex_girl.png'),
                          Positioned.fill(
                              child: Container(
                            alignment: Alignment.center,
                            child: Text('我是女生',
                                style: TextStyle(
                                    color: const Color(0xFF333333), fontSize: 18.sp, fontWeight: FontWeight.w500)),
                          )),
                          if (sex == 1)
                            Positioned(
                                top: 20.h,
                                right: 35.w,
                                child: Image.asset('assets/app/images/user_edit/user_edit_check_s.png', width: 28.w)),
                        ],
                      ).onTap(() {
                        sex = configModel?.step1?.gender?.male?.val ?? 1;

                        setState(() {});
                      }),
                      SizedBox(height: 20.h),
                      Stack(
                        children: [
                          Image.asset('assets/app/images/user_edit/user_edit_sex_boy.png'),
                          Positioned.fill(
                              child: Container(
                            alignment: Alignment.center,
                            child: Text('我是男生',
                                style: TextStyle(
                                    color: const Color(0xFF333333), fontSize: 18.sp, fontWeight: FontWeight.w500)),
                          )),
                          if (sex == 2)
                            Positioned(
                                top: 20.h,
                                right: 35.w,
                                child: Image.asset('assets/app/images/user_edit/user_edit_check_s.png', width: 28.w)),
                        ],
                      ).onTap(() {
                        sex = configModel?.step1?.gender?.female?.val ?? 1;
                        setState(() {});
                      }),
                    ],
                  ),
                ),
                bottomNavigationBar: Padding(
                  padding: EdgeInsets.only(left: 20.w, right: 20.w, bottom: Get.bottomBarHeight + 20),
                  child: BrnBigMainButton(
                    title: "下一步 （1/3）".tr,
                    width: double.infinity - 32 * 2,
                    bgColor: const Color(0xFF25D4D0),
                    bgDisEnableColor: const Color(0xFF25D4D0).withOpacity(0.6),
                    themeData: BrnButtonConfig(bigButtonRadius: 255, bigButtonHeight: 45.h, bigButtonFontSize: 16.sp),
                    isEnable: sex != 0,
                    onTap: () {
                      req = req.copyWith(gender: sex.toString());
                      Get.to(UserInfoEditAvaterPage(req: req, configModel: configModel!));
                    },
                  ),
                )),
          ],
        ),
      ),
    );
  }
}

void show() {}
